package listnode;

/**
 * @Description: 合并两个有序链表21.java
 * @Author: meiyu
 * @Date: 2021/11/23 9:21
 */
public class 合并两个有序链表21 {

    // 1.递归,升序
    public ListNode mergeTwoLists(ListNode l1, ListNode l2) {
        if (l1 == null) {
            return l2;
        } else if (l2 == null) {
            return l1;
        } else if (l1.getVal() < l2.getVal()) {
//            return mergeTwoLists(l1.next, l2);
            l1.next = mergeTwoLists(l1.next, l2);
            return l1;
        } else {
//            return mergeTwoLists(l1, l2.next);
            l2.next = mergeTwoLists(l1, l2.next);
            return l2;
        }
    }

    // 迭代 TODO

}
